// src/main/java/dao/VideoDao.java
package dao;

import model.Video;
import util.DatabaseUtil;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class VideoDao {
    private static final Logger LOGGER = Logger.getLogger(VideoDao.class.getName());

    public boolean addVideo(Video video) {
        String sql = "INSERT INTO videos (title, file_path, view_count) VALUES (?, ?, 0)";

        try (Connection conn = DatabaseUtil.getConnection();
             PreparedStatement stmt = conn.prepareStatement(sql)) {

            stmt.setString(1, video.getTitle());
            stmt.setString(2, video.getFilePath());

            int affectedRows = stmt.executeUpdate();
            LOGGER.log(Level.INFO, "新增视频成功，影响行数: " + affectedRows);
            return affectedRows > 0;

        } catch (SQLException e) {
            LOGGER.log(Level.SEVERE, "新增视频失败: " + e.getMessage(), e);
            return false;
        }
    }
}